home *** CD-ROM | disk | FTP | other *** search
/ Apple Developer Connection Student Program / ADC Tools Sampler CD Disk 3 1999.iso / Documentation / Books / Learn Java on the Macintosh / Learn Java Projects / 09.03 - employee 3 / Employee3.java < prev    next >
Text File  |  1996-04-22  |  2KB  |  69 lines

  1. /* -------------------------------------------------------------
  2. This applet shows when you might want to use the variable "this".
  3.  
  4. Java's classes: Applet    (applet)
  5.                 System    (lang)
  6.  
  7. Custom classes: Employee3
  8.                 Employee
  9.  
  10. ------------------------------------------------------------- */
  11. public class Employee3 extends java.applet.Applet {
  12.  
  13.    Employee e1;
  14.    Employee e2;
  15.    Employee e3;
  16.  
  17.    public void init() {
  18.       e1 = new Employee();
  19.       e1.initialize(10, 20);
  20.       
  21.       e2 = new Employee();
  22.       e2.initialize(18, 38);
  23.       
  24.       e3 = new Employee();
  25.       e3.initialize(12, 52);
  26.    }
  27.    
  28.    public void start() {
  29.       System.out.println("");
  30.       System.out.println("Employee 1:");
  31.       e1.displayInfo();      
  32.       
  33.       System.out.println("");
  34.       System.out.println("Employee 2:");
  35.       e2.displayInfo();      
  36.       
  37.       System.out.println("");
  38.       System.out.println("Employee 3:");
  39.       e3.displayInfo();      
  40.    }
  41. }
  42.  
  43. class Employee {
  44.    int hourlyWage;
  45.    int hoursWorked;
  46.    
  47.    int earnedIncome() {
  48.       return hourlyWage * hoursWorked;
  49.    }
  50.       
  51.    void displayInfo() {
  52.       int earnedIncome;
  53.       
  54.       System.out.println("hourly wage = " + hourlyWage);
  55.       System.out.println("hours worked = " + hoursWorked);
  56.       
  57.       earnedIncome = earnedIncome();
  58.       System.out.println("earned income = " + earnedIncome);
  59.    }
  60.    
  61.    void initialize(int hourlyWage, int hoursWorked) {
  62.       this.hourlyWage = hourlyWage;
  63.       this.hoursWorked = hoursWorked;
  64.    }
  65.  
  66. }
  67.  
  68.  
  69.